home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2486 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: cnn.Princeton.EDU!franck!tim
  2. From: tim@franck (Tim Hollebeek)
  3. Newsgroups: comp.lang.misc,comp.lang.perl.misc,comp.lang.tcl,comp.lang.c,comp.lang.java
  4. Subject: Re: Relative Speed of Perl vs. Tcl vs. C
  5. Followup-To: comp.lang.misc,comp.lang.perl.misc,comp.lang.tcl,comp.lang.c,comp.lang.java
  6. Date: 21 Jan 1996 22:14:39 GMT
  7. Organization: Princeton University
  8. Message-ID: <4dudsf$187@cnn.Princeton.EDU>
  9. References: <4dhuoj$cbe@shellx.best.com> <9602122.8425@mulga.cs.mu.OZ.AU>
  10. NNTP-Posting-Host: franck.princeton.edu
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Fergus Henderson (fjh@munta.cs.mu.OZ.AU) wrote:
  14. : yogi@shellx.best.com (Yogi) writes:
  15.  
  16. : >Can't seem to find any info on statements I have read that seem to conflict:
  17.  
  18. : Have you ever heard the phrase "Lies, damned lies, and benchmarks"?
  19.  
  20. : >Somewhere I have read that Perl coded grep runs as fast or faster than C
  21. : >coded grep in Unix. (Larry Wall wrote this, correct me if I'm wrong.)
  22.  
  23. : Sounds quite likely to be true.
  24. : For this specific task, Perl could easily be as fast as C.
  25.  
  26. You have to remember that Perl program will be about 3 lines long, and
  27. most of the CPU intensive work is regexp matching and file operations.
  28. In Perl, both of those are very highly optimized C routines.
  29. Therefore, such a 'Perl' program is essentially a C program; you are
  30. using it for exactly what Perl was designed to do very well.
  31.  
  32. : >And in a CGI-web book I read that Perl is an interpreted language that runs
  33. : >10 times slower than C.
  34.  
  35. : For most programs, that is probably true.
  36.  
  37. BTW, 10 times is about typical for bytecode compilers; 7-15 or so is a
  38. reasonable range, except where the time is dominated by 'high level'
  39. constructs, where it can be 2-3 or much lower, as noted above.
  40.  
  41. : >So what's the real answer, or are both statements true somehow? I know that
  42. : >Perl can run faster or slower depending on how you code it, (C too) and 
  43. : >so I guess you would have to find the fastest C code for a particular function
  44. : >and similar fastest Perl code (or Tcl) and compare THOSE programs to get 
  45. : >a definative answer.
  46.  
  47. An important point, though, is that all 'reasonably' written C programs
  48. will run within a factor of 2 or so of 'about as fast as you can get,
  49. while for some problems, Perl won't be able to break through about a
  50. factor of 7 or so, even if you are a Perl expert.  Languages like Perl
  51. tend to be important in context where you are willing to give up the
  52. speed advantage for some other features of the language.  Let's face
  53. it; very few applications need C's speed any more.
  54.  
  55. --
  56. Tim Hollebeek      | Everything above is a true statement, for sufficiently
  57. PChem Grad Student | false values of true.
  58. Princeton Univ.    | tim@wfn-shop.princeton.edu
  59. -------------------| http://wfn-shop.princeton.edu/~tim
  60.